package com.dataextend.controller;


import com.alibaba.fastjson.JSONObject;
import com.dataextend.dto.Logindto;
import com.dataextend.dto.RequestList;
import com.dataextend.entity.SysRoleMybatis;
import com.dataextend.entity.SysUserMybatis;
import com.dataextend.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 *  用户/角色/权限相关 controller
 */
@RestController
public class ShiroController {

    @Autowired
    private SysUserService sysUserService;


    /**
     * 登录
     */
    @RequestMapping(value = "/sys/login", method = RequestMethod.POST)
    public JSONObject authLogin(@RequestBody Logindto logindto){
        return sysUserService.authLogin(logindto);
    }


    /**
     * 查询当前登录用户的信息
     */
    @RequestMapping(value = "/sys/getInfo", method = RequestMethod.POST)
    public JSONObject getInfo(){
        return sysUserService.getInfo();
    }


    /**
     * 退出
     */
    @RequestMapping(value = "/sys/logout", method = RequestMethod.POST)
    public JSONObject logout(){
        return sysUserService.logout();
    }


    /**
     * 查询用户列表
     */
    @RequestMapping(value = "/user/Userlist", method = RequestMethod.POST)
    public JSONObject GetAllUsers(@RequestBody RequestList requestList) {
        return sysUserService.listUser(requestList.getPageNo(),requestList.getPageSize());
    }


    /**
     * 添加用户
     */
    @RequestMapping(value = "/user/addUser", method = RequestMethod.POST)
    public JSONObject AddUser(@RequestBody SysUserMybatis sysUserMybatis){
        return sysUserService.addUser(sysUserMybatis);
    }


    /**
     * 修改用户
     */
    @RequestMapping(value = "/user/updateUser", method = RequestMethod.POST)
    public JSONObject UpdateUser(@RequestBody SysUserMybatis sysUserMybatis){
        return sysUserService.updateUser(sysUserMybatis);
    }



    /**
     * 角色列表
     */
    @RequestMapping(value = "/role/listRole", method = RequestMethod.POST)
    public JSONObject listRole(){
        return sysUserService.listRole();
    }


    /**
     * 查询所有权限,给角色分配权限时调用
     */
    @RequestMapping(value = "/listAllPermission", method = RequestMethod.POST)
    public JSONObject listAllPermission(){
        System.out.println("userService.listAllPermission() " + sysUserService.listAllPermission());
        return sysUserService.listAllPermission();
    }


    /**
     * 新增角色
     */
    @RequestMapping(value = "/addRole", method = RequestMethod.POST)
    public JSONObject addRole(@RequestBody SysRoleMybatis sysRoleMybatis){
        return sysUserService.addRole(sysRoleMybatis);
    }


    /**
     * 修改角色
     */


    /**
     * 删除角色
     */
    @RequestMapping(value = "/deleteRole", method = RequestMethod.POST)
    public JSONObject deleteRole(@RequestBody SysRoleMybatis sysRoleMybatis){
        return sysUserService.deleteRole(sysRoleMybatis);
    }



}


